#include <iostream>
#include <cstring>
#include <numeric>
#include <cmath>
#include <vector>
#include <algorithm>
#include <ctime>
using namespace std;

#define ISLESS(a, b) if ((a) != (b)) return (a) < (b)
#define ISGREATER(a, b) if ((a) != (b)) return (a) > (b)

const int MAXPARTS = 20;
const int MAXHEIGHT = 1200;
const int MAXBOOKS = 1500;
const int TimeLimit = (int)(1.85 * CLOCKS_PER_SEC);

int timerCounter = 0;

int GetTime()
{
	return clock();
}

class Book 
{
public:
	int m_height;
	int m_width;
	int m_value;
	int m_initialIndex;
	Book(int h, int w, int v, int ind) : 
	m_height(h),
		m_width(w),
		m_value(v),
		m_initialIndex(ind) {}
	Book() {}
};



bool booksValueGreater(const Book &a, const Book &b)
{
	double p = 0.99;
	return a.m_value * pow(b.m_width, p) > b.m_value * pow(a.m_width, p);
}

class BookSelection
{
	bool timeLimitExceeded;
	int totalHeight;
	int totalWidth;
	Book *books;
	int booksSize;
	vector<int> heights;
	int count;
	int bestPoints;
	int curPoints;
	vector<int> bestHeights;
	int *result;
	int *bestResult;
	vector<int> memo;

	inline void GetBooksWithBestValue(
		int booksIndexes[], int booksSize, 
		int height, int &width, 
		int ret[], int &retSize,
		int rest[], int &restSize)
	{
		int curWidth = 0;
		retSize = 0;
		restSize = 0;
		for (int t = 0; t < booksSize; ++t) {
			int i = booksIndexes[t];
			if (books[i].m_height <= height && books[i].m_width + curWidth <= width) {
				ret[retSize++] = i;
				curWidth += books[i].m_width;
			} else {
				rest[restSize++] = i;
			}
		}
		width -= curWidth;
	}

	int parts[MAXPARTS];
	int partsSize;
	int bestParts[MAXPARTS + 1][MAXPARTS];
	int bestPartsSize[MAXPARTS + 1];
	int prevBestParts[MAXPARTS + 1][MAXPARTS];
	int prevBestPartsSize[MAXPARTS + 1];
	double A, B;

	int &GetMemo(int n)
	{
		if (n >= memo.size()) memo.resize(n + 1);
		return memo[n];
	}

	bool CheckTLE()
	{
		if (timeLimitExceeded) {	
			return true;
		}
		//static int timerCounter = 0;
		if ((++timerCounter & ((1<<10) - 1)) == 0) {
			int curTime = GetTime();
			if (curTime > TimeLimit) {
				timeLimitExceeded = true;
				cerr << "Clock break: " << (double)curTime / CLOCKS_PER_SEC << endl;
				return true;
			}
		}
		return false;
	}

	void Rec(int sum, int last, int restHeight, int shelfCount, int booksIndexes[], int booksSize, int maxParts, int readyParts)
	{
		if (timeLimitExceeded) {
			return;
		}

		if (sum < last * (maxParts - readyParts)) {
			return;
		}

		if (curPoints * 10000 < totalWidth * (totalHeight - restHeight) * 9) {
			return;
		}

		//int pos = restHeight * 1000 + last;
		int pos = restHeight * 1000 + last;
		int &memoPoints = GetMemo(pos);
		if (memoPoints > 0 && memoPoints * 10000 >= 10080 * curPoints) {
			return;
		}
		memoPoints = curPoints;

		if (readyParts == maxParts) {
			if (curPoints >= bestPoints) {
				//bestParts[maxParts] = parts;
				memcpy(bestParts[maxParts], parts, sizeof(parts[0]) * partsSize);
				bestPartsSize[maxParts] = partsSize;
			}
		}

		if (readyParts == maxParts) {
			++count;
			if (curPoints >= bestPoints) {
				bestPoints = curPoints;
				memcpy(bestResult, result, sizeof(result[0]) * this->booksSize);
			}
			return;
		}

		if (CheckTLE()) {
			return;
		}

		int *sub = new int[booksSize];
		int subSize = 0;
		int *rest = new int[booksSize];
		int restSize = 0;

		for (int i = last; i <= sum; ++i) {
			if (timeLimitExceeded) {
				break;
			}
			int curHeight = (restHeight - 10) * i / sum;
			int shelfWidth = totalWidth;
			int maxHeight = 0;
			int points = 0;
			bool okParts = true;

			parts[partsSize++] = i;

			if (partsSize < prevBestPartsSize[maxParts]) {
				int cur = parts[partsSize - 1];
				if (cur < prevBestParts[maxParts][shelfCount] * 2 - A) okParts = false;
				if (cur > prevBestParts[maxParts][shelfCount] * 2 + B) okParts = false;
			} else if (partsSize == prevBestPartsSize[maxParts]) {
				int cur = parts[partsSize - 1];
				if (cur < prevBestParts[maxParts][shelfCount] * 2 - 5) okParts = false;
				if (cur > prevBestParts[maxParts][shelfCount] * 2 + 5) okParts = false;
			}

			if (okParts) {
				GetBooksWithBestValue(booksIndexes, booksSize, curHeight, shelfWidth, sub, subSize, rest, restSize);
				for (int t = 0; t < subSize; ++t) {
					int j = sub[t];
					if (maxHeight < books[j].m_height) {
						maxHeight = books[j].m_height;
					}
					result[books[j].m_initialIndex] = shelfCount;
					points += books[j].m_value;
				}
				maxHeight = curHeight;
				curPoints += points;

				if (points > 0 && shelfWidth < 0.1 * totalWidth) {
					Rec(sum - i, i, restHeight - maxHeight - 10, shelfCount + 1, rest, restSize, maxParts, readyParts + 1);
				}

				for (int t = 0; t < subSize; ++t) {
					int j = sub[t];
					result[books[j].m_initialIndex] = -1;
				}
				curPoints -= points;
			}

			--partsSize;
		}

		delete [] sub;
		delete [] rest;
	}

public:

	vector <int> arrange(int H, int W, vector <int> bookHeights, vector <int> bookWidths, vector <int> bookValues) {

		cerr << H << endl;
		cerr << W << endl;
		int X = bookHeights.size();
		cerr << X << endl;
		//for(int i = 0; i<X; i++)
		//    cerr << bookHeights[i] << (i + 1 < X ? "\t" : "\n");
		//for(int i = 0; i<X; i++)
		//    cerr << bookWidths[i] << (i + 1 < X ? "\t" : "\n");
		//for(int i = 0; i<X; i++)
		//    cerr << bookValues[i] << (i + 1 < X ? "\t" : "\n");

		booksSize = bookHeights.size();
		books = new Book[booksSize];
		for (int i = 0; i < bookHeights.size(); ++i) {
			books[i] = Book(bookHeights[i], bookWidths[i], bookValues[i], i);
			//cerr << bookHeights[i] << "\t" << bookWidths[i] << "\t" << bookValues[i] << endl;
		}

		sort(books, books + booksSize, booksValueGreater);

		timeLimitExceeded = false;

		totalHeight = H;
		totalWidth = W;

		count = 0;

		int sums[] = {20,	40,	80,	160,	320, 	640,	1280,	2560, 	5120,	10240,	20480,	40960,	81920};
		int CA[] =   {-1,	1,  2,  1,		1,		1,		1, 		1, 		1,		1, 		1, 		1, 		1};
		int CB[] =   {-1,	1,  2,  1,		1,		1,		1,		1, 		1,		1, 		1, 		1, 		1};
		int sumsSize = sizeof(sums) / sizeof(sums[0]);

		vector <int> ret(booksSize, -1);
		int retPoints = 0;
		memo.clear();

		result = new int[booksSize];
		bestResult = new int[booksSize];
		int *booksIndexes = new int [booksSize];
		int booksIndexesSize = 0;
		for (int i = 0; i < booksSize; ++i) {
			booksIndexes[booksIndexesSize++] = i;
		}

		partsSize = 0;
		memset(bestPartsSize, 0, sizeof(bestPartsSize));
		memset(prevBestPartsSize, 0, sizeof(prevBestPartsSize));

		int bestMaxParts = 0;

		for (int i = 0; i < sumsSize; ++i) {
			if (CheckTLE()) {
				break;
			}

			A = CA[i];
			B = CB[i];

			memset(result, -1, sizeof(result[0]) * booksSize);
			memset(bestResult, -1, sizeof(bestResult[0]) * booksSize);
			static int start = 1;
			static int end = MAXPARTS;
			int prevPoints = 0;
			for (int maxParts = start; maxParts <= end; ++maxParts) {
				if (timeLimitExceeded) {
					break;
				}

				curPoints = 0;
				bestPoints = 0;
				Rec(sums[i], 1, H, 0, booksIndexes, booksIndexesSize, maxParts, 0);
				//prevBestParts[maxParts] = bestParts[maxParts];
				memcpy(prevBestParts[maxParts], bestParts[maxParts], sizeof(prevBestParts[maxParts][0]) * bestPartsSize[maxParts]);
				prevBestPartsSize[maxParts] = bestPartsSize[maxParts];

				//cerr << sums[i] << endl;
				//cerr << "parts: " << maxParts << ", bestPoints: " << bestPoints << endl;
				//for (int t = 0; t < bestParts[maxParts].size(); ++t)
				//    cerr << bestParts[maxParts][t] << (t + 1 < bestParts[maxParts].size() ? " " : "\n");
				//cerr << count << endl << endl;

				if (bestPoints >= retPoints) {
					bestMaxParts = maxParts;
					retPoints = bestPoints;
					ret = vector<int>(bestResult, bestResult + booksSize);
				}

				if (bestPoints < prevPoints) {
					break;
				}
				prevPoints = bestPoints;
			}

			int d = i < 3 ? 1 : 0;
			start = max(1, bestMaxParts - d);
			end = min(MAXPARTS, bestMaxParts + d);
		}

		cerr << "timerCounter = " << timerCounter << endl;
		delete [] books;
		delete [] result;
		delete [] bestResult;

		return ret;
	}
};

int nextInt()
{
	int n;
	cin >> n;
	return n;
}

void println(int n)
{
	cout << n << endl;
}

int main()
{
	int H = nextInt();
	int W = nextInt();
	int X = nextInt();
	vector<int> bookHeights(X);
	for(int i = 0; i<X; i++)
		bookHeights[i] = nextInt();
	vector<int> bookWidths(X);
	for(int i = 0; i<X; i++)
		bookWidths[i] = nextInt();
	vector<int> bookValues(X);
	for(int i = 0; i<X; i++)
		bookValues[i] = nextInt();
	BookSelection bs;
	vector<int> ret = bs.arrange(H, W, bookHeights, bookWidths, bookValues);
	for(int i = 0; i<X; i++)
		println(ret[i]);

	cerr << "FinistTime = " << (double)clock() / CLOCKS_PER_SEC << endl;

	return 0;
}
